/**
 * Decider.cpp
 * Coyright (c) 2009 Xiaofeng Gu. All Rights Reserved.
 * Author : Xiaofeng Gu
 *
 * Creation Data : 2009/06/11
 */

#include "stdafx.h"
#include "Decider.h"
#include <math.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

HRESULT CDecider::OnExecute()
{
	HRESULT hr = S_OK;
	hr = __super::OnExecute();
	if (hr != S_OK)
	{
		return hr;
	}

	CDeciderProcessCard* pDeciderProcessCard = GetBlockInfo<CDeciderProcessCard>(DECIDERPROCESSCARD);
	Families* pFamiles = pDeciderProcessCard->GetFamilies();
	for (Families::iterator itFa = pFamiles->begin(); itFa != pFamiles->end(); itFa ++)
	{
		CFamily* pFamily = *itFa;
		Knots* pKnots = pFamily->GetKnots();
		long lCount = (long)(pKnots->size());
		for (long i = 0; i < lCount-1; i ++)
		{
			CKnot* pKnot = (*pKnots)[i];
			CKnot* pKnot2 = (*pKnots)[i + 1];

			long DeltaTime = pKnot2->GetTime() - pKnot->GetTime();

			// path definition
			CTransPath* pPath = pKnot->GetPath();
			pPath->SetItemCount(DeltaTime);
			pPath->Create();

			// difference definition
			Diffs* pDiffs = pKnot->GetDiffs();
			for (Diffs::iterator it = pDiffs->begin();
				it != pDiffs->end(); it ++)
			{
				NodeDifference* pNodeDif = *it;
				pNodeDif->deltaDirection.angle /= (DeltaTime - 1);
				pNodeDif->deltaNormal.angle /= (DeltaTime - 1);
				pNodeDif->deltaSize.factor = pow(pNodeDif->deltaSize.factor, 1.0/ (DeltaTime - 1));
			}
		}
	}

	return S_OK;
}